#include <lpc23xx.h>
#include <RTL.h>
#include "LCD.h"

OS_TID  id1,id2;
OS_SEM  sem1;
__task void task1(void);
__task void task2(void);

int main(void)
{
lcd_init();					   
lcd_clear();				  
set_cursor(3,0);			   
lcd_print("Semaphore");
FIO2DIR=0x000000FF;
os_sem_init (sem1, 1);
os_sys_init_prio (task1,0x01);
	 
}
__task void task1(void){
   OS_RESULT ret;
   id1 = os_tsk_self ();
   id2 = os_tsk_create (task2,0x01);
   
	while(1)
	{
	ret = os_sem_wait (sem1, 1);
    if (ret != OS_R_TMO) {
      /* If there was no time-out the semaphore was aquired */
      FIO2SET=0x000000F0;
	  FIO2CLR=0x0000000F;	
      os_sem_send (sem1);
    }
	
	os_dly_wait(50);	
	}

}
__task void task2(void){
	while(1)
	{
	os_sem_wait (sem1, 0xFFFF);
	FIO2SET=0x0000000F;
	FIO2CLR=0x000000F0;	
	
	os_sem_send (sem1);
	os_dly_wait(50);
	}

}



